//
//  HGlobalReminder.m
//  HMusicPlayer
//
//  Created by Hament on 14/9/30.
//  Copyright (c) 2014年 HJ. All rights reserved.
//

#import "HGlobalReminder.h"
#import "HCoreConfig.h"
#import <QuartzCore/QuartzCore.h>

@implementation HGlobalReminder



//type: 0 is loading style, 1 is handsuccess, 2 is handelfail ,3 just display text
-(id)initWithFrame:(NSRect)frameRect remindTx:(NSString*)title type:(NSUInteger)type{
    self=[super initWithFrame:frameRect];
    
    self.remindType=type;
    
    self.remindTf=[[NSTextField alloc] initWithFrame:NSMakeRect(45, 3, frameRect.size.width-45, 40)];
    self.remindTf.font=[NSFont systemFontOfSize:15];
    self.remindTf.textColor=[NSColor whiteColor];
    self.remindTf.alignment=NSCenterTextAlignment;
    self.remindTf.backgroundColor=[NSColor clearColor];
    //[self.remindTf.cell setLineBreakMode:NSLineBreakByCharWrapping];
    [self.remindTf setEditable:NO];
    [self.remindTf setBordered:NO];
    
    if (title) {
        self.remindTf.stringValue=title;
    } else {
        self.remindTf.stringValue=NSLocalizedString(@"Processing...", nil);
    }
    [self addSubview:self.remindTf];
    
    
    switch (type) {
            //loading
        case 0:{
            //32 X 32
//            self.processIndicator=[[NSProgressIndicator alloc] initWithFrame:CGRectMake(20, (HReminderHeigh - 32) /2, 32, 32)];
            
            self.animationView=[[NSView alloc] initWithFrame:NSMakeRect(10, 10, 30, 30)];
            [self.animationView setWantsLayer:YES];
            [self.animationView.layer setOpacity:0.8];
            [self addSubview:self.animationView];
            
        }
            break;
            //success with image
        case 1:{
            
            self.remindImg=[[NSImageView alloc] initWithFrame:NSMakeRect(10, 10, 30, 30)];
            self.remindImg.image=[NSImage imageNamed:@"success_remind"];
            [self addSubview:self.remindImg];
            
        }
            break;
            //failed with image
        case 2:{
            self.remindImg=[[NSImageView alloc] initWithFrame:NSMakeRect(10, 10, 30, 30)];
            self.remindImg.image=[NSImage imageNamed:@"fail"];
            [self addSubview:self.remindImg];
        }
            break;
            //just text remind
        case 3:{
            
            self.remindTf.frame= NSMakeRect(10, 10, HReminderWidth-10*2, 30);
            self.remindTf.font=[NSFont systemFontOfSize:18];
        }
            break;
        default:
            break;
    }
    
    
    

    

    
    return self;
}


- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    NSRect selectionRect = NSInsetRect(self.bounds, 0, 0);
    [RGBA(43, 47, 52, 1.0) setFill];
    NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:5 yRadius:5];
    [selectionPath fill];
    // Drawing code here.
}







-(void)starRemindAnimationWithText:(NSString* )title{


    if (title) {
        self.remindTf.stringValue=title;
    } else {
        self.remindTf.stringValue=NSLocalizedString(@"Processing...", nil);
    }

    

    
    CAKeyframeAnimation *  anim2 = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
    [anim2 setCalculationMode:kCAAnimationDiscrete];
    [anim2 setDuration:2.0f];
    [anim2 setRepeatCount:HUGE_VALF];
    [anim2 setValues:@[[NSImage imageNamed:@"con_state_1"],[NSImage imageNamed:@"con_state_2"],[NSImage imageNamed:@"con_state_3"]] ];
    
    [self.animationView.layer addAnimation:anim2 forKey:@"iconRotate"];
    
    
   


}




-(void)stopRemindAnimation{


[self.animationView.layer removeAnimationForKey:@"iconRotate"];//删除动画


}





@end
